<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>库存管理</title>
</head>
<body class="hold-transition skin-black sidebar-mini">
<div th:replace="common/fragment :: link"></div>
<div class="wrapper">
    <div th:replace="common/fragment :: navbar"></div>
    <div th:replace="common/fragment :: menu"></div>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>库存编辑</h1>
        </section>
        <section class="content">
            <div class="box">
                <form class="form-horizontal" action="/warehouse/saveOrUpdate" method="post" id="editForm">
                    <input type="hidden" th:value="${warehouse?.id}" name="id">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="address" class="col-sm-1 control-label">地址：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" id="address" name="address"
                                   th:value="${warehouse?.address}"
                                   placeholder="请输入地址">
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="tel" class="col-sm-1 control-label">电话：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" id="tel" name="tel" th:value="${warehouse?.tel}"
                                   placeholder="请输入联系电话">
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="num" class="col-sm-1 control-label">数量：</label>
                        <div class="col-sm-4">
                            <input type="number" class="form-control" id="num" name="num" th:value="${warehouse?.num}"
                                   placeholder="请输入库存数量">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label class="col-sm-1 control-label">状态：</label>
                        <input name="status" type="checkbox" data-size="small" value="1"
                               th:checked="${warehouse?.status}">
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="goods.id" class="col-sm-1 control-label">商品：</label>
                        <div class="col-sm-4">
                            <select class="form-control" name="goods.id" id="goods.id">
                                <option value="">全部</option>
                                <option th:each="goods,stat:${goodsList}"
                                        th:value="${goods.id}"
                                        th:text="${goods.name}"
                                        th:selected="${goods.id == warehouse?.goods?.id}">
                                </option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-offset-1 col-sm-6">
                            <button id="submitBtn" type="submit" class="btn btn-primary">保存</button>
                            <button type="reset" class="btn btn-danger">重置</button>
                        </div>
                    </div>

                </form>
            </div>
        </section>
    </div>
    <div th:replace="common/fragment :: footer"></div>
</div>
<script>
    $("#editForm").bootstrapValidator({
        feedbackIcons: { // 图标
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: { // 配置要验证的字段
            address: {
                validators: { // 验证的规则
                    notEmpty: { // 不能为空
                        message: "地址必填" // 错误时的提示信息
                    }
                }
            },
            tel: {
                validators: {
                    notEmpty: { // 不能为空
                        message: "电话必填" // 错误时的提示信息
                    }
                }
            },
            num: {
                validators: {
                    notEmpty: { // 不能为空
                        message: "数量必填" // 错误时的提示信息
                    }
                }
            }
        }
    })/*.on('success.form.bv', function(e) {
            // TODO 这里可以改成用异步的方式提交表单
            e.preventDefault(); // 阻止默认事件
            // Get the form instance
            var $form = $("#editForm");
            // Use Ajax to submit form data
            $.post('/employee/saveOrUpdate', $form.serialize(), function(data) {
                if(data.success) {
                    location.href = '/employee/list';
                } else {
                    alert(data.msg);
                }
            });
        });*/
</script>
</body>
</html>